<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <canvas id="c" width="300" height="300" style="border: 1px solid #ccc;"></canvas>

    <script>
        const cnv = document.getElementById('c')
        const cxt = cnv.getContext('2d')

        //绘制矩形
        cxt.moveTo(50,50)
        cxt.lineTo(200,50)
        cxt.lineTo(200,120)
        cxt.lineTo(50,120)
        cxt.lineTo(50,50)//需要闭合，又或者使用closePath()的方法实现闭合，推荐使用claosePath()

        cxt.stroke()

    </script>
</body>
</html>